package week04.graph01;

import java.util.List;

/**
 * Created by zhangxiaokun on 2018/2/28.
 */
public class TestGraphic {
    public static void main(String[] args) {

        Graphic graphic = constructGraphi();

        graphic.draw();
        List<Graphic> leafsList = graphic.getAllChild();
        showWhat(leafsList);

        System.out.println("\n\n");
        graphic.remove( graphic.getChild(leafsList.size()-1) );
        graphic.draw();
        showWhat(leafsList);

    }

    public static void showWhat(List<Graphic> list) {
        for (Graphic bean : list) {
            System.out.println(bean);
            if (bean.isPicture()) {
                showWhat(bean.getAllChild());
            }
        }
    }


    private static Graphic constructGraphi() {
        Graphic graphic = new Picture();
        graphic.add(new Line());
        graphic.add(new Rectangle());
        Graphic picture = new Picture();
        graphic.add(picture);

        picture.add(new Text());
        Graphic p01 = new Picture();
        picture.add(p01);
        p01.add(new Line());

        Graphic p02 = new Picture();
        picture.add(p02);
        p02.add(new Text());

        return graphic;
    }
}
